package com.unione.unione_base.view

import android.content.Context
import android.icu.lang.UCharacter.GraphemeClusterBreak.T
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.Nullable
import androidx.fragment.app.Fragment
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.viewbinding.ViewBinding
import kotlinx.coroutines.CoroutineScope


abstract class BaseFragment<VB : ViewBinding> : Fragment() {
    protected var _binding: VB? = null

    protected val binding get() = _binding!!


    val mContext: Context
        get() = requireContext()
    val mLifecycleOwner: LifecycleOwner
        get() = this
    val scope: CoroutineScope
        get() = lifecycleScope

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
    ): View? {
        _binding = onCreateViewBinding(inflater, container)
        return _binding?.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        init()
    }


    protected abstract fun onCreateViewBinding(
        inflater: LayoutInflater,
        @Nullable parent: ViewGroup?
    ): VB

    abstract fun init()

    override fun onDestroyView() {
        super.onDestroyView()
        _binding = null

    }


}